package top.someapp.dxf2dsvg.jfx;

import javafx.application.Platform;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.web.WebView;
import org.apache.batik.swing.JSVGScrollPane;

import javax.annotation.Nonnull;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author zwz
 * Created on 2020-04-23
 */
public class SceneMain implements JfxController {
    private static SceneMain instance;
    JfxContext jfxContext;
    File workDir;
    List<File> cadFiles = new ArrayList<>();

    @FXML
    ToolBar toolBar;
    @FXML
    MenuItem menuFileQuit;
    @FXML
    MenuItem menuFileOptions;
    @FXML
    MenuItem menuHelpAbout;
    @FXML
    ListView<String> cadFileList;
    @FXML
    WebView webView;
    @FXML
    Label lblPreviewFileName;
    @FXML
    SwingNode swingContainer;
    @FXML
    Label lblStatus;
    @FXML
    ProgressBar pgBar;
    JSVGScrollPane jsvgScrollPane;

    public SceneMain() {
        instance = this;
    }

    @Override
    public void onCreate(@Nonnull JfxContext jfxContext) {
        this.jfxContext = jfxContext;
        if (jsvgScrollPane != null)
            return;

        workDir = new File(System.getProperty("user.dir"), "work");
        if (!workDir.exists())
            workDir.mkdirs();

        new SceneMainToolBar(this);
        menuFileQuit.setOnAction(this::onMenuAction);
        menuFileOptions.setOnAction(this::onMenuAction);
        menuHelpAbout.setOnAction(this::onMenuAction);
        lblPreviewFileName.setText("");
    }

    private void onMenuAction(ActionEvent event) {
        Object source = event.getSource();
        if (Objects.equals(source, menuFileQuit)) {
            Platform.exit();
        } else if (Objects.equals(source, menuFileOptions)) {

        } else if (Objects.equals(source, menuHelpAbout)) {
            JfxDialog dialog = new JfxDialog("/jfx/About.fxml");
            dialog.setTitle(I18N.getString("menu.help.about"));
            dialog.show();
        }
    }

}
